﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.IO;

namespace Shared
{
    public static class ConfigurationExtension
    {
        public static IServiceCollection AddConfig(this IServiceCollection services)
        {
            var path = Path.Combine(Environment.CurrentDirectory, "Config");
            var files = Directory.GetFiles(path, "*.json", SearchOption.AllDirectories);

            var builder = new ConfigurationBuilder();
            builder.SetBasePath(path);
            foreach(var file in files)
            {
                builder.AddJsonFile(file);
            }
            builder.AddEnvironmentVariables();

            return services;
        }
    }
}
